import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:study_flutter/wyfg/project/shop/page/cart_page.dart';
import 'package:study_flutter/wyfg/project/shop/page/home_page.dart';
import 'package:study_flutter/wyfg/project/shop/page/mine_page.dart';
import 'package:study_flutter/wyfg/project/shop/page/sort_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class IndexPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  List<BottomNavigationBarItem> _bottom_list = [
    BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), title: Text("首页")),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.search), title: Text("分类")),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.shopping_cart), title: Text("购物车")),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.person), title: Text("我的"))
  ];

  List<Widget> tab_page = [WHomePage(), WSortPage(), WCartPage(), WMinePage()];

  int curtterIndex = 0;

  var curtterPage;

  @override
  void initState() {
    curtterPage = tab_page[curtterIndex];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context,width: 375,height:812 );
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        fixedColor:Colors.pinkAccent ,
        currentIndex: curtterIndex,
        items: _bottom_list,
        selectedFontSize: 12,
        unselectedFontSize: 12,
        iconSize: 24,
        onTap:(index){
          setState(() {
            curtterIndex=index;
            curtterPage=tab_page[curtterIndex];
          });
        },
      ),
      body: IndexedStack(
        index: curtterIndex,
        children: tab_page,
      ),
    );
  }
}